import os
import requests

url = "http://172.31.30.3:8777/api/local_doc_qa/upload_files"

for folder_name in os.listdir("/data/yf_center/jingbo/QAnything_pro/0305/zsk"):
    # print(folder_name)
    # if folder_name != "问答类":
    #     continue
    print(folder_name)
    folder_path = f"/data/yf_center/jingbo/QAnything_pro/0305/zsk/{folder_name}"  # 文件所在文件夹，注意是文件夹！！
    data = {
        "user_id": "zzp",
        "kb_id": "KB163dd069627044bca421e1ecfa856260",
            "mode": "soft"
    }

    files = []
    for root, dirs, file_names in os.walk(folder_path):
        for file_name in file_names:
            # if file_name.endswith(".md"):  # 这里只上传后缀是md的文件，请按需修改，支持类型：
            file_path = os.path.join(root, file_name)
            files.append(("files", open(file_path, "rb")))
            if len(files) >= 5000:
                response = requests.post(url, files=files, data=data)
                print(response.text)
                files = []

    response = requests.post(url, files=files, data=data)
    print(response.text)